composite data type
Composite data types are declared and defined in TYPE statements in the prolog, before the
first function declaration. The names of these user-defined types become keywords
that can be used just like built-in type names.
Composite variables are fixed-size collections of fixed-size, named components.
Every component is one of the following:
Built-in simple numeric type.
Fixed-size string.
Previously defined composite type.
Fixed size one-dimensional array of any of the above.
composite type declaration
Composite types are created by TYPE blocks in the prolog, before the first function is
declared. The name of the type follows the TYPE statement. The types and names
of the components are defined on subsequent lines, one component per line. An END
TYPE statement marks the end of the type definition. The following example shows how
a composite type called VICTIM is created.
TYPE VICTIM
USHORT .number
' victim # from 0 to 65535
STRING*50 .name
' victim name up to 50
bytes
STRING*50 .address[3] ' array with (4) 50 byte
strings
SLONG .zipcode
' zip code part of address
GIANT .phone
' victim phone number
UBYTE .kids
' number of kids victim
has
UBYTE .ages[15]
' age of victim and up to 14 kids
FUNCADDR .Poison (STRING) ' function that poisons the victim
FUNCADDR .Shoot (XLONG) ' function that shoots the victim
FUNCADDR .BuryAlive () ' function that buries the
victim
FUNCADDR .Drown () ' function
that drowns the victim
END TYPE
Creating a composite type fixes several things:
The overall size of variables of the specified type.
The name of each component.
The type of each component.
The size of each component.
The location of each component within the composite.
Components are naturally aligned. In other words, the addresses of SSHORT, USHORT
components are multiples of 2, the addresses of SLONG, ULONG, SINGLE components are
multiples of 4, and the addresses of GIANT, DOUBLE components are multiples of 8.
Sometimes space must be left after a component so the next component begins in
natural alignment. This unused space is called padding. Careful ordering of
elements can eliminate or reduce padding. Composite types larger than 65535 bytes
cannot be declared or defined.